package com.electric.electric.mapper.admin;


import com.electric.electric.POJO.Entity.admin.SysPermission;
import com.electric.electric.POJO.Entity.admin.SysRole;
import com.electric.electric.POJO.Entity.admin.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AuthenticationMapper {

    @Select("select * from sys_user where username = #{username}")
    SysUser selectUserByUsername(String username);

    // 根据用户ID查询角色
    @Select("SELECT r.* FROM sys_role r " +
            "INNER JOIN sys_user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    List<SysRole> selectRolesByUserId(Integer userId);

    // 根据角色ID查询权限
    @Select("SELECT p.* FROM sys_permission p " +
            "INNER JOIN sys_role_permission rp ON p.id = rp.perm_id " +
            "WHERE rp.role_id = #{roleId}")
    List<SysPermission> selectPermissionsByRoleId(Integer roleId);
}
